-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix wrong byte_pointer passed to auto_indent_proc #562
Conversation
@@ -1645,7 +1645,7 @@ def call_completion_proc_with_checking_args(pre, target, post) | |||
@line = ' ' * new_indent + @line.lstrip | |||
|
|||
new_indent = nil | |||
result = @auto_indent_proc.(new_lines[0..-2], @line_index - 1, (new_lines[-2].size + 1), false) | |||
result = @auto_indent_proc.(new_lines[0..-2], @line_index - 1, (new_lines[@line_index - 1].bytesize + 1), false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Third arg is a byte_pointer, so it should use bytesize
instead of size
I think the intention of this line is to pass line_number
and new_lines[line_number].bytesize + 1
.
But new_lines[-2]
was not always new_lines[@line_index - 1]
. Fixed the index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation! Would you mind extracting these arguments into local variables so they'd be self-documenting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I let it as is?
It would be readable if it is assigned to local variable, but I have problem with naming.
prev_line_index = @line_index - 1
prev_line = lines[prev_line_index]
This seems good, but there is @previous_line_index
with probably different meaning. I don't have alternate idea that is not confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Let's keep it as it is then 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -1645,7 +1645,7 @@ def call_completion_proc_with_checking_args(pre, target, post) | |||
@line = ' ' * new_indent + @line.lstrip | |||
|
|||
new_indent = nil | |||
result = @auto_indent_proc.(new_lines[0..-2], @line_index - 1, (new_lines[-2].size + 1), false) | |||
result = @auto_indent_proc.(new_lines[0..-2], @line_index - 1, (new_lines[@line_index - 1].bytesize + 1), false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation! Would you mind extracting these arguments into local variables so they'd be self-documenting?
Fixes byte_pointer passed to auto_indent_proc when inserting newline.
If there is multiline character, wrong byte_pointer causes invalid byte sequence error.
Fixes #553 and ruby/irb#627